package jp.seraph.same.view;

import javax.swing.JLabel;

import jp.seraph.same.model.JointModel;
import jp.seraph.same.model.JointModelListener;

public class JointValueLabel extends JLabel {
    public JointValueLabel(JointModel aModel) {
        mListener = new JointModelListener() {

            public void JointAngleChanged(JointModel aSender) {
                JointValueLabel.this.setText(Double.toString(aSender.getJointAngleAsDegree()));
            }
        };

        this.setModel(aModel);
    }

    private JointModel mModel;
    private JointModelListener mListener;
    private static final long serialVersionUID = 10L;

    public void setModel(JointModel aModel) {
        if (mModel != null)
            mModel.removeListener(mListener);

        mModel = aModel;
        mModel.addListener(mListener);

        this.setText(Double.toString(mModel.getJointAngleAsDegree()));
    }
}
